//
//  AppDelegateDecotor.h
//  LoanOwer
//
//  Created by jk on 2019/5/18.
//  Copyright © 2019 jk. All rights reserved.
//

#import "AppDelegateDecotor.h"
#import "HomePageController.h"
#import "SideMenuViewController.h"
#import "NetworkManager.h"
#import "MyNaController.h"
#import "MFSideMenuContainerViewController.h"
@interface AppDelegateDecotor()
@property (nonatomic ,strong)HomePageController *demoController;
@property (nonatomic ,strong)MyNaController *navigationController;
@property (nonatomic ,strong)SideMenuViewController *leftMenuViewController;
@end

@implementation AppDelegateDecotor
+ (instancetype)shareDector{
    static dispatch_once_t onceToken;
    static AppDelegateDecotor * dector = nil;
    dispatch_once(&onceToken, ^{
        dector = [[AppDelegateDecotor alloc]init];
        [dector setUpApp];
    });
    return dector;
}
- (void)setUpApp{
    NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
    [parmDict setObject:@"init" forKey:@"act"];
    
    NetworkManager *netHttp = [[NetworkManager alloc] init];
    NSDictionary *initDict =[netHttp sendAndWaitResponse:parmDict addUserPwd:true useDataCached:true];
    netHttp = nil;
    
    if (initDict != nil){
        [GlobalVariables sharedInstance].program_title = [initDict toString:@"program_title"];
        [GlobalVariables sharedInstance].site_domain = [initDict toString:@"site_domain"];
        [GlobalVariables sharedInstance].kf_phone = [initDict toString:@"kf_phone"];
        [GlobalVariables sharedInstance].kf_email = [initDict toString:@"kf_email"];
        [GlobalVariables sharedInstance].about_info = [initDict toString:@"about_info"];
        
        NSArray *iddealcate  = [initDict objectForKey:@"deal_cate_list"];
        
        NSMutableArray *tmp_list2 = [[NSMutableArray alloc] init];
        [GlobalVariables sharedInstance].deal_cate_list = tmp_list2;
        
        if (iddealcate != nil && [iddealcate count] > 0){
            NSDictionary *tmpListDict = [initDict objectForKey:@"deal_cate_list"];
            for (NSDictionary *dict in tmpListDict) {
                DealCate *dealCate = [[DealCate alloc] init];
                [dealCate setJson:dict];
                [[GlobalVariables sharedInstance].deal_cate_list addObject:dealCate];
            }
        }
    }
}

- (HomePageController *)demoController{
    if (!_demoController) {
        _demoController = [[HomePageController alloc] init];;
    }
    return _demoController;
}

- (UINavigationController *)navigationController{
    if (!_navigationController) {
        _navigationController = [[MyNaController alloc]
                                 initWithRootViewController:[self demoController]];
    }
    return _navigationController;
}
- (SideMenuViewController *)leftMenuViewController{
    if (!_leftMenuViewController) {
        _leftMenuViewController = [[SideMenuViewController alloc] init];;
    }
    return _leftMenuViewController;
}
- (UIViewController *)rootVC{
    if (!_rootVC) {
        _rootVC = [MFSideMenuContainerViewController containerWithCenterViewController:self.navigationController
                                                        leftMenuViewController:self.leftMenuViewController
                                                        rightMenuViewController:nil];
    }
    return _rootVC;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
}


- (void)applicationWillTerminate:(UIApplication *)application {
}


//9.0之前使用
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return NO;
}

//NOTE: 9.0以后使用新API接口
- (BOOL)application:(UIApplication *)app openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
    return NO;
}

@end
